package org.springcloud.wisdom.springcloud_03_freshman.admin.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springcloud.wisdom.springcloud_03_freshman.student.entity.Goods;

import java.util.List;

@Mapper
public interface AdminGoodsDao {
    @Select("<script>" +
            "SELECT * FROM goods" +
            "  <where>" +
            "    <if test=\"dept != null\">" +
            "     dept = #{dept} " +
            "    </if>" +
            "    <if test=\"receiveStatus != null\">" +
            "   and  receiveStatus = #{receiveStatus} " +
            "    </if>" +
            "</where>"+
            " ORDER BY" +
            "  CASE " +
            "    WHEN receiveStatus = '已领取' THEN 1" +
            "    WHEN receiveStatus = '未领取' THEN 2" +
            "    ELSE 3" +
            "  END," +
            "  receiveStatus ASC "+
            "limit #{start},#{size}"+
            "</script>")
    public List<Goods> getGoodsByCons(int start, int size, String receiveStatus, Integer dept);

    @Select("<script>" +
            "SELECT count(*) FROM goods" +
            "  <where>" +
            "    <if test=\"receiveStatus != null\">" +
            "      receiveStatus = #{receiveStatus}" +
            "    </if>" +
            "    <if test=\"dept != null\">" +
            "     and dept = #{dept} " +
            "    </if>" +
            "</where>"+
            "</script>")
    public int countGoods(String receiveStatus,Integer dept);
}
